package com.lemon.smartsafetynew.ui.adapter.record;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.ledger.LedgerBuildingCheckItemVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;
import com.lemon.smartsafetynew.util.patrol.CheckItemUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/10/21.
 */

public class RecordBuildingCheckItemListAdapter extends LemonRcvAdapter<LedgerBuildingCheckItemVo> {

    private RecyclerTClickListener<LedgerBuildingCheckItemVo> mListener;

    public RecordBuildingCheckItemListAdapter(@Nullable List<LedgerBuildingCheckItemVo> data,
                                              RecyclerTClickListener<LedgerBuildingCheckItemVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<LedgerBuildingCheckItemVo> {

        private LedgerBuildingCheckItemVo mData;
        private int mPosition;

        @Bind(R.id.item_name_tv)
        TextView itemNameTv;
        @Bind(R.id.item_status_tv)
        TextView itemStatusTv;
        @Bind(R.id.item_abnormal_count_tv)
        TextView itemAbnormalCountTv;
        @Bind(R.id.layout)
        LinearLayout layout;


        @Override
        public int getLayoutResId() {
            return R.layout.item_record_check_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(LedgerBuildingCheckItemVo ledgerBuildingCheckItemVo, int position) {

            mData = ledgerBuildingCheckItemVo;
            mPosition = position;

            itemNameTv.setText("巡查点位名称：" + CommonUtil.avoidNullString(ledgerBuildingCheckItemVo.getItem_name()));
            itemStatusTv.setText("巡查点状态：" + CheckItemUtil.getCheckItemStatusString(ledgerBuildingCheckItemVo.getStatus()));
            itemStatusTv.setTextColor(Color.parseColor(CheckItemUtil.getCheckItemStatusColor(ledgerBuildingCheckItemVo.getStatus())));
            itemAbnormalCountTv.setText("巡查点异常次数：" + CommonUtil.avoidNullString(ledgerBuildingCheckItemVo.getRed_num()));

        }
    }
}